package tothreedesignmodel.visitor;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author lzhphantom
 * @description
 * @date 创建于 23:57 2020/8/1
 * @modified
 */
public class ObjectStructure {
    private final List<Element> list = new ArrayList<>();

    public void accept(Visitor visitor) {
        list.forEach(item -> item.accept(visitor));
    }

    public void add(Element el) {
        list.add(el);
    }

    public void remove(Element el) {
        list.remove(el);
    }

    public static void main(String[] args) {
        ObjectStructure os=new ObjectStructure();
        os.add(new ConcreteElementA());
        os.add(new ConcreteElementB());
        Visitor visitor=new ConcreteVisitorA();
        os.accept(visitor);
        System.out.println("------------------------");
        visitor=new ConcreteVisitorB();
        os.accept(visitor);
    }
}
